package steed.ext.domain.user;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

import org.hibernate.Hibernate;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;

import com.arjuna.ats.internal.arjuna.recovery.PeriodicRecovery.Status;

import steed.domain.annotation.ValidateReg;
import steed.hibernatemaster.domain.BaseRelationalDatabaseDomain;
import steed.util.base.RegUtil;

@Entity
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class Power extends BaseRelationalDatabaseDomain{
	private static final long serialVersionUID = 8841822962310540390L;
	@ValidateReg(reg={RegUtil.regChineseAndChar})
	private String name;
	private String description;
	
	/**
	 * 权限级别,0系统 ,>0 用户自定义级别,若@power注解没定义级别,则默认为1
	 */
	private Integer level;
	/**
	 * 状态,0正常使用,1停用(部分action功能暂时用不到,但是power注解一样会被扫描到,<br>
	 * 如果把没用到的权限显示到权限分配页面,不是很合理)
	 */
	private Integer status;
	
	
	public Integer getStatus() {
		return status;
	}
	public void setStatus(Integer status) {
		this.status = status;
	}
	public Integer getLevel() {
		return level;
	}
	public void setLevel(Integer level) {
		this.level = level;
	}
	public Power() {
	}
	
	
	@Override
	public boolean save() {
		if (status == null) {
			status = 0;
		}
		return super.save();
	}
	public Power(String name, Integer level) {
		super();
		this.name = name;
		this.level = level;
	}
	public Power(String name) {
		this.name = name;
	}
	
	@Column(length=64)
	@Id
	@GenericGenerator(name="generator",strategy="assigned")
	@GeneratedValue(generator="generator")
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	/*@Override
	public boolean equals(Object obj) {
		if (obj instanceof Power){
			String name2 = ((Power) obj).getName();
			if (name != null) {
				return name.equals(name2);
			}
			return name2 == null;
		}else{
			return false;
		}
	}*/
	/*@Override
	public int hashCode() {
		if (name == null) {
			return super.hashCode();
		}
		return this.name.hashCode();
	}*/
	@Override
	public void initialize() {
		Hibernate.initialize(this);
	}
	@Override
	public void initializeAll() {
		initialize();
	}
}
